package com.doit.day04

import scala.util.Sorting

/**
 * 需求2：对7个订单的金额大小的降序排列
 * 需求4：统计每一个用户的订单总额
 * 需求6：找出每一种品类中金额最大的订单
 */
object OrderingDemo {
  def main(args: Array[String]): Unit = {
    val orders= Array(ScalaOrder("u001", "o001", "g001", "c002", 998.99, 1),
      ScalaOrder("u002", "o001", "g003", "c002", 98.99, 2),
      ScalaOrder("u001", "o003", "g003", "c003", 8.99, 1),
      ScalaOrder("u003", "o002", "g002", "c003", 9.99, 22),
      ScalaOrder("u001", "o003", "g002", "c004", 99.99, 3),
      ScalaOrder("u004", "o003", "g002", "c001", 118.99, 4),
      ScalaOrder("u002", "o002", "g001", "c001", 228.99, 8))

    Sorting.quickSort(orders)(new Ordering[ScalaOrder] {
      override def compare(x: ScalaOrder, y: ScalaOrder) =(y.price*y.goods_num).toInt.compareTo( (x.price*x.goods_num).toInt)
    })







  }
}


case class ScalaOrder(
                       user_id: String
                       , order_id: String
                       , goods_id: String
                       , category_id: String
                       , price: Double
                       , goods_num: Integer
                     ) extends Ordered[ScalaOrder] {
  override def compare(that: ScalaOrder): Int = -(price*goods_num - that.price*that.goods_num).toInt
}
